package com.gupao.singleton;

import com.gupao.singleton.register.EnumSingleton;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class TestEnumSingleton {
    public static void main(String[] args) {
        EnumSingleton e1 = EnumSingleton.getInstance();
        EnumSingleton e2 = null;

        e1.setData(new Object());
        FileOutputStream fos = null;

        try {
            fos = new FileOutputStream("EnumSingleton.obj");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(e1);
            oos.flush();
            oos.close();

            FileInputStream fis = new FileInputStream("EnumSingleton.obj");
            ObjectInputStream ois = new ObjectInputStream(fis);
            e2 = (EnumSingleton) ois.readObject();
            ois.close();

            System.out.println(e1.getData());
            System.out.println(e2.getData());
            System.out.println(e1.getData() == e2.getData());

        } catch (Exception e) {
            e.printStackTrace();
        }

        /**
         * 执行结果：
         *          java.lang.Object@378bf509
         *          java.lang.Object@378bf509
         *          true
         */
    }
}
